#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;

vec2 f(vec2 z, vec2 c) {
    return mat2(z, -z.y, z.x) * z + c;
}


void main() {
    vec2 uv = gl_FragCoord.xy / u_resolution;
    vec2 center = vec2(0.,0.);
    float scale = 1.2;
    vec2 c = center + 4.0 * (uv - vec2(0.5)) / scale;
    bool escaped = false;
    vec2 z = vec2(0.);
    int j;
    float iterations = 256;
    for(int i = 0;i < 65535;i++) {
        if (i > iterations) break;
        j = i; 
        z = f(z,c);
        if (length(z) > 2.) {
            escaped = true;
            break;
        }
    }
    gl_FragColor.rgb = escaped ? vec3(float(j)) / float(iterations) : vec3(0.);
    gl_FragColor.a = 1.;
}